package com.kingyea.mobilepolice.kim.controller;

import com.alibaba.fastjson.JSON;
import com.kingyea.mobilepolice.kim.bean.KimUserFriendsVo;
import com.kingyea.mobilepolice.kim.service.KimUserFriendsService;
import com.kingyea.mobilepolice.security.SecurityUtils;
import com.kingyea.mobilepolice.system.Result;
import com.kingyea.mobilepolice.user.bean.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author linxiuzi
 * @version v1.0.0
 * @description This is a class
 * @date Created in 2018.04.08 15:04
 */

@RestController
@RequestMapping("/user-friends")
public class KimUserFriendsController {

    private Logger logger = LoggerFactory.getLogger(KimUserFriendsController.class);

    @Autowired
    private KimUserFriendsService userFriendsService;

    /**
     * 获取当前用户好友信息
     *
     * @param request
     * @param response
     * @return
     */
    @GetMapping("/getCurrentFriednsInfo")
    public Result<KimUserFriendsVo> getCurrentUserFriendsInfo(HttpServletRequest request, HttpServletResponse response) {
        // 开放跨域
        // 允许跨域
        response.setHeader("Access-Control-Allow-Origin","*");
        // 获取当前用户
        User user = SecurityUtils.getCurrentUser();
        System.out.println(JSON.toJSONString(user));
        return userFriendsService.getUserFriendsByUserId(user.getUserId());
    }

    @GetMapping("/generateFriendsForTest")
    public Result<KimUserFriendsVo> generateFriendsForTest(HttpServletRequest request, HttpServletResponse response) {
        // 开放跨域
        // 允许跨域
        response.setHeader("Access-Control-Allow-Origin","*");
        // 获取当前用户
        return userFriendsService.generateFriendsForTest();
    }
    
}
